//公共脚本函数

//根据操作结果进行提示
function actionResultTip(result) {
	if (result && result.success == true) {
		$(this).alertmsg("info",result.msg==undefined ? "操作成功！":result.msg);
	} else if (result && result.success == false) {
		$(this).alertmsg("warn",result.msg==undefined ? "操作失败！":result.msg);
	} else {
		$(this).alertmsg("warn","服务端未返回操作结果！");
	}
}
//根据操作结果进行提示
function ajaxDoneTip(done) {
	if(done!=null){
		var code = done.statusCode;
		if(code=="200"){
			$(this).alertmsg("info",done.message==undefined ? "操作成功！":done.message);
		}else if(code=="300"){
			$(this).alertmsg("error",done.message==undefined ? "操作失败！":done.message);
		}else if(code=="301"){
			$(this).alertmsg("error",done.message==undefined ? "操作超时！":done.message);
		}else{
			$(this).alertmsg("warn","服务端未返回操作结果！");
		}
	}else{
		$(this).alertmsg("warn","服务器返回异常！");
	}
}
//发送ajax同步请求
function ajaxJsonSync(url, data) {
	var result;
	$.ajax({
		url : url,
		type : "post",
		dataType : "json",
		data : data,
		success : function(r) {
			result = r;
		},
		async : false
	});
	return result;
}

//获取当前页签的tree对象
function getZTree(treeId){
	var treeObj = $.fn.zTree.getZTreeObj("treeId");
	return treeObj;
}

//获取表单下的所有元素值，返回json对象
function getFormData(formId){
	var obj = {};
	var ipts = $.CurrentNavtab.find(formId+" :input");
	var $e,name,val,type,tag;
	ipts.each(function(i,e){
		$e = $(e);
		name = $e.attr("name");
		type = $e.attr("type");
		tag = e.tagName;
		if("TEXTAREA"==tag){
			obj[name]=$e.val();
		}else if("INPUT"==tag){
			if("radio"==type){
				var check = e.checked;
				if(check){
					obj[name]= $e.val();
				}
			}else{
				obj[name]= $e.val();
			}
		}
	});
	return obj;
}

//设置表单下的所有元素值，传入表单id与json对象
function setFormData(formId,data){
	if(data==null)return;
	var ipts = $.CurrentNavtab.find(formId+" :input");
	var $e,name,val,type,tag,_val;
	ipts.each(function(i,e){
		$e = $(e);
		name = $e.attr("name");
		type = $e.attr("type");
		tag = e.tagName;
		val = data[name];
		if("TEXTAREA"==tag){
			$e.val(val);
		}else if("INPUT"==tag){
			if("radio"==type){
				_val = $(e).val();
				if(val==_val){
					$(e).iCheck('check');
				}
			}else{
				$e.val(val);
			}
		}
	});
	/**
	var $e,type,tag,_val,_e;
	$.each(data,function(name,val){
		$e = $.CurrentNavtab.find(formId+" :input[name='"+name+"']");
		if($e.length==0)return;
		_e = $e.get(0);
		type = $e.attr("type");
		tag = _e.tagName;
		if("INPUT"==tag){
			if("radio"==type){
				$e.each(function(i,e){
					_val = $(e).val();
					if(val==_val){
						$(e).iCheck('check');
					}
				});
			}else{
				$e.val(val);
			}
		}else if("TEXTAREA"==tag){
			$e.val(val);
		}
	});
	**/
}